package com.hzc.springchan.strategy.restrequest.impl;

import com.hzc.springchan.bean.request.Request;
import com.hzc.springchan.config.resthelp.RequestConcurrent;
import com.hzc.springchan.constant.System;
import com.hzc.springchan.strategy.restrequest.IRestRequestStrategy;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Get rest请求参数封装策略类
 * @author chen990627
 * @date 2022/10/18
 */
@Service(System.RestRequestStrategy.GET)
public class GetRestRequestStrategy implements IRestRequestStrategy {

    @Autowired
    private RequestConcurrent requestConcurrent;

    @Override
    public void restRequest(JoinPoint point) {

        Object[] values = point.getArgs();
        String[] argNames = ((MethodSignature) point.getSignature()).getParameterNames();

        int len = values.length;
        Request request = new Request();
        for (int i = 0; i < len; i++) {
            request.put(argNames[i], values[i]);
        }
        requestConcurrent.putCurrentRequest(request);
    }
}
